package com.liner;

public class IntegerDemo {
    public static void main(String[] args) {
        Integer i1 = new Integer(5); //装箱
        Integer i2 = new Integer(5);
        System.out.println(i1 == i2);   //比较地址值 false
        System.out.println(i1.equals(i2)); // true

        Integer i3 = Integer.valueOf(500);
        Integer i4 = Integer.valueOf(500);
        System.out.println(i3 == i4);   //比较地址值 false
        System.out.println(i3.equals(i4)); // true


        //valueOf 复用1个字节(-128,127)范围内的数据
        Integer i5 = Integer.valueOf(120);
        Integer i6 = Integer.valueOf(120);
        System.out.println(i5 == i6);   //true
        System.out.println(i5.equals(i6));  //true


        //将包装类型转换为基本类型
        int i = i3.intValue(); //拆箱

        //jdk1.5 自动拆装箱，触发了自动装箱特性
        Integer i7 = 123;

        //包装类常用操作
        int maxValue = Integer.MAX_VALUE;
        int minValue = Integer.MIN_VALUE;
        System.out.println("maxValue: " + maxValue + " minValue: " + minValue);

        String value = "123";
        int i8 = Integer.parseInt(value);
        //NumberFormatException 数字类型转换异常
        String value1 = "123.123";
        int i9 = Integer.parseInt(value); //NumberFormatException


    }
}
